package com.qn.common.base;


import com.qn.common.base.model.ResponseCode;
import com.qn.common.base.model.ResponseData;
import com.qn.common.base.model.ResponseMode;
import com.qn.common.base.model.ResponseRows;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */
import java.util.List;

public class BaseControlle {

    private ResponseMode base(Integer code, String msg) {
        return new ResponseMode(code, msg);
    }

    public ResponseMode success(String msg) {
        return base(ResponseCode.SUCCESS.code(), msg);
    }

    public ResponseMode success() {
        return base(ResponseCode.SUCCESS.code(), "成功");
    }

    public ResponseMode error(String msg) {
        return base(ResponseCode.ERROR.code(), msg);
    }

    public ResponseMode error() {
        return base(ResponseCode.ERROR.code(), "成功");
    }


    private <T> ResponseData baseD(Integer code, String msg, T data) {
        return new ResponseData<T>(code, msg, data);
    }

    public <T> ResponseData successD(String msg, T data) {
        return baseD(ResponseCode.SUCCESS.code(), msg, data);
    }

    public <T> ResponseData successD(T data) {
        return baseD(ResponseCode.SUCCESS.code(), "成功", data);
    }

    public <T> ResponseData successD() {
        return baseD(ResponseCode.SUCCESS.code(), "成功", null);
    }

    public <T> ResponseData errorD(String msg) {
        return baseD(ResponseCode.ERROR.code(), msg, null);
    }

    public <T> ResponseData errorD() {
        return baseD(ResponseCode.ERROR.code(), "成功", null);
    }


    private <T> ResponseRows baseR(Integer code, String msg, List<T> rows) {
        return new ResponseRows<T>(code, msg, rows);
    }

    public <T> ResponseRows successR(String msg, List<T> rows) {
        return baseR(ResponseCode.SUCCESS.code(), msg, rows);
    }

    public <T> ResponseRows successR(List<T> rows) {
        return baseR(ResponseCode.SUCCESS.code(), "成功", rows);
    }

    public <T> ResponseRows successR() {
        return baseR(ResponseCode.SUCCESS.code(), "成功", null);
    }

    public <T> ResponseRows errorR(String msg) {
        return baseR(ResponseCode.ERROR.code(), msg, null);
    }

    public <T> ResponseRows errorR() {
        return baseR(ResponseCode.ERROR.code(), "成功", null);
    }

}
